'use strict';

module.exports = appInfo => {
    const config = {};

    /**
     * 数据配置文件保存路径
     * @type {string}
     */
    config.rootPath = '/opt/pmc-run';
    config.logsPath = config.rootPath + '/logs';
    config.infoPath = config.rootPath + '/info';
    config.configInfoPath = config.infoPath + '/config';
    config.sysConfigFile = config.infoPath + '/iiot-config.json';

    config.logger = {
        dir: config.logsPath,
        level: 'INFO',
        outputJSON: true
    };

    config.customLogger = {
        scheduleLogger: {
            consoleLevel: 'NONE',
            file: config.logsPath + '/egg-schedule.log',
        },
    };

    // config.schedule = {
    //     directory: [],
    // };
    /**
     * mongo
     */
    const mongoUrl = '127.0.0.1:22900';
    // const mongoUrl = '127.0.0.1:28080';
    // const mongoUrl = '119.45.189.48:28080';
    // const mongoUrl = 'www.treec.cn:28080';

    const baseUser = 'pmc';
    const dbPwd = 'Afei!168';
    const dbBase = 'pmc';
    const baseUrl = `mongodb://${baseUser}:${dbPwd}@${mongoUrl}/${dbBase}`;
    // const baseUrl = `mongodb://${mongoUrl}/${dbBase}`;

    const busUser = 'pmcBus';
    const dbBus = 'pmcBus';
    const busUrl = `mongodb://${busUser}:${dbPwd}@${mongoUrl}/${dbBus}`;
    // const busUrl = `mongodb://${mongoUrl}/${dbBus}`;

    config.mongoose = {
        clients: {
            pmc: {
                url: baseUrl,
                options: {
                    useNewUrlParser: true,useUnifiedTopology: true,
                    autoReconnect: true,
                    reconnectTries: Number.MAX_VALUE, // Never stop trying to reconnect
                    reconnectInterval: 10000, // Reconnect every 500ms
                    useFindAndModify:false
                },
            },
            pmcBus: {
                url: busUrl,
                options: {
                    useNewUrlParser: true,useUnifiedTopology: true,
                    autoReconnect: true,
                    reconnectTries: Number.MAX_VALUE, // Never stop trying to reconnect
                    reconnectInterval: 10000, // Reconnect every 500ms
                    useFindAndModify:false
                },
            }
        }
    };
    config.iiotConfig = {
        logger: {
            'level': 'WARN'
        },
        mqtt: {
            enable: true,
            // url: 'tcp://www.iotmqtt.cn',
            // port: 21883,
            url: 'tcp://60.173.17.240',
            port: 10049,
            usr: 'mqtt',
            pwd: 'ztesoft'
        },
        rootPath: '/opt',
        defaultDeviceOnlineSpaceTime: 30
    };
    return config;
};
